#ifndef PROXY_EVENT_HANDLER_FACTORY_IMPL_H
#define PROXY_EVENT_HANDLER_FACTORY_IMPL_H

#include "ProxyEventHandler.h"
#include "singleton.h"
#include "FlowChart.h"

class CProxyEventHandlerFactory : public IProxyEventHandlerFactory, public CSingleton<CProxyEventHandlerFactory>
{
    friend class CSingleton<CProxyEventHandlerFactory>;
public:
    virtual IProxyEventHanlder * Create(CProxy *);
};

class CProxyEventHandler : public IProxyEventHanlder
{
public:
    // explicit constructor
    CProxyEventHandler(CProxy * pProxy);

    //// event when established connection with client
    //virtual void OnCliConnected() ;

    // event when disconnected from client
    virtual void OnCliDisconnected() ;

    // event when any error occurred
    virtual void OnCliError(int32 error_code, const char * error_message) ;

    // event when received message from client
    virtual void OnCliReceive(const char * message, uint32 message_length) ;

    // event when established connection with server
    virtual void OnSvrConnected() ;

    // event when disconnected from server
    virtual void OnSvrDisconnected() ;

    //// event when any error occurred
    //virtual void OnSvrError(int32 error_code, const char * error_message) ;

    // event when received message from server
    virtual void OnSvrReceive(const char * message, uint32 message_length) ;

    // event when received message from pipe
    virtual void OnRecvPipeMsg(utility::network::PIPEID pipeID, const char * message, uint32 message_length);

    CProxy * GetProxy();

protected:
    void _NotifyDBOffline();
private:
    CProxy * m_pProxy;
    Machine m_stateMachine;

};


#endif  // endif of PROXY_EVENT_HANDLER_FACTORY_IMPL_H
